From: Jonathan Dieter Date: Wed, 6 Jun 2018 10:24:02 +0000 (+0300) Subject: Make sure we cast to unsigned long when using printf, and use ftruncate X-Git-Tag: archive/raspbian/1.1.9+ds1-1+rpi1~1^2~237 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=3544c998d7e8f317946eed560a5f3205baea7346;p=zchunk.git Make sure we cast to unsigned long when using printf, and use ftruncate return value Signed-off-by: Jonathan Dieter --- diff --git a/src/unzck.c b/src/unzck.c index 9f30e3b..a55172c 100644 --- a/src/unzck.c +++ b/src/unzck.c @@ -145,7 +145,7 @@ int main (int argc, char *argv[]) { if(!zck_close(zck)) goto error2; if(arguments.log_level <= ZCK_LOG_INFO) - printf("Decompressed %lu bytes\n", total); + printf("Decompressed %lu bytes\n", (unsigned long)total); good_exit = True; error2: free(data); diff --git a/src/zck.c b/src/zck.c index a3a688d..5b0e2a8 100644 --- a/src/zck.c +++ b/src/zck.c @@ -264,7 +264,7 @@ int main (int argc, char *argv[]) { if(arguments.log_level <= ZCK_LOG_INFO) { printf("Using buzhash algorithm for automatic chunking\n"); - printf("Window size: %lu\n", buzhash_width); + printf("Window size: %lu\n", (unsigned long)buzhash_width); } while(cur_loc < data + in_size) { uint32_t bh = 0; @@ -297,8 +297,9 @@ int main (int argc, char *argv[]) { if(arguments.log_level <= ZCK_LOG_INFO) { zckIndex *idx = zck_get_index(zck); printf("Wrote %lu bytes in %lu chunks\n", - zck_get_data_length(zck) + zck_get_header_length(zck), - idx->count); + (unsigned long)(zck_get_data_length(zck) + + zck_get_header_length(zck)), + (unsigned long)idx->count); } zck_free(&zck); diff --git a/src/zck_dl.c b/src/zck_dl.c index 35a2526..8b7f6fc 100644 --- a/src/zck_dl.c +++ b/src/zck_dl.c @@ -214,11 +214,12 @@ int dl_bytes(dlCtx *dl_ctx, char *url, size_t bytes, size_t start, if(log_level <= ZCK_LOG_DEBUG) printf("Downloading %lu bytes at position %lu\n", - start+bytes-*buffer_len, *buffer_len); + (unsigned long)start+bytes-*buffer_len, + (unsigned long)*buffer_len); *buffer_len += start + bytes - *buffer_len; if(lseek(fd, start, SEEK_SET) == -1) { - printf("Seek to byte %lu of temporary file failed: %s\n", start, - strerror(errno)); + printf("Seek to byte %lu of temporary file failed: %s\n", + (unsigned long)start, strerror(errno)); return 0; } } @@ -283,7 +284,7 @@ int main (int argc, char *argv[]) { CURL *curl_ctx = curl_easy_init(); if(!curl_ctx) { printf("Unable to allocate %lu bytes for curl context\n", - sizeof(CURL)); + (unsigned long)sizeof(CURL)); exit(10); } @@ -323,7 +324,11 @@ int main (int argc, char *argv[]) { } /* Download the full file */ lseek(dst_fd, 0, SEEK_SET); - ftruncate(dst_fd, 0); + if(ftruncate(dst_fd, 0) < 0) { + perror(NULL); + exit_val = 10; + goto out; + } dlCtx dl_ctx = {0}; dl_ctx.dl = dl; dl_ctx.curl = curl_ctx; @@ -349,7 +354,11 @@ int main (int argc, char *argv[]) { printf("Missing chunks: 0\n"); printf("Downloaded %lu bytes\n", (long unsigned)zck_dl_get_bytes_downloaded(dl)); - ftruncate(dst_fd, zck_get_length(zck_tgt)); + if(ftruncate(dst_fd, zck_get_length(zck_tgt)) < 0) { + perror(NULL); + exit_val = 10; + goto out; + } exit_val = 0; goto out; } @@ -397,7 +406,11 @@ int main (int argc, char *argv[]) { } printf("Downloaded %lu bytes\n", (long unsigned)zck_dl_get_bytes_downloaded(dl)); - ftruncate(dst_fd, zck_get_length(zck_tgt)); + if(ftruncate(dst_fd, zck_get_length(zck_tgt)) < 0) { + perror(NULL); + exit_val = 10; + goto out; + } switch(zck_validate_data_checksum(dl->zck)) { case -1: diff --git a/test/empty.c b/test/empty.c index 865f173..1bb5d7d 100644 --- a/test/empty.c +++ b/test/empty.c @@ -89,7 +89,7 @@ int main (int argc, char *argv[]) { memset(data, 0, 1000); len = zck_read(zck, data, 1000); if(len > 0) { - printf("%li bytes read, but file should be empty\n", len); + printf("%li bytes read, but file should be empty\n", (long)len); exit(1); } if(!zck_close(zck))